<script setup>
	import { onShow } from "@dcloudio/uni-app"
	import { ref } from "vue";
	import { uniFetch } from '../../../utils/fetch';
	onShow(() => {
		console.log(12333);
		getlist()
	})
	const page = ref(1);
	const pageSize = ref(5);
	const list = ref([]);
	const getlist = async () => {
		console.log("1111");
		const res = await uniFetch({
			url: "/driver/messages/page",
			data: {
				page: page.value,
				pageSize: pageSize.value,
				contentType: 200
			}
		})
		console.log(res, "res");
		if (res.data.code !== 200) {
			return uni.utils.toast("数据加载失败")
		} else {
			if(res.data.data.items!==null){
		list.value = [...list.value,...res.data.data.items]
				
			}else{
		// list.value = [...list.value,...[]]
			uni.showToast({
				icon:"none",
				title:"暂无更多数据"
			})	
			}
				page.value+=1
				refreshtrigger.value=false
		}
	
	}
	const refreshtrigger=ref(true)
	const xlsx=()=>{
		console.log("下拉刷新");
		refreshtrigger.value=true
		list.value=[];
		page.value=1;
		getlist()
		
		console.log(refreshtrigger.value);
	}
	const scrolltolower=()=>{
		console.log(123333444);
		getlist()
	}
	const ckxq=()=>{
		console.log("1233333444");
	}
	const allread=()=>{
		uniFetch({
			url:"/driver/messages/readAll/200",
			method:"PUT"
		}).then(res=>{
			console.log(res);
			if(res.data.code == 200){
				uni.showToast({
					icon:"success",
					title:"成功"
				})
			}
		})
	}
</script>
<template>
  <scroll-view class="scroll-view" @refresherrefresh="xlsx" :refresher-triggered="refreshtrigger" @scrolltolower="scrolltolower" refresher-enabled scroll-y>
    <view class="scroll-view-wrapper">
      <view class="message-action" @click="allread">
        <text class="iconfont icon-clear"></text>
        全部已读
      </view>
      <uni-list :border="false">
        <uni-list-item
		v-for="item in list"
          :to="'/subpkg_message/content/index?id='+item.id+'&info='+JSON.stringify(item)"
          ellipsis="1"
          :title="item.content"
          :rightText="item.created"
        >
          <template v-slot:header>
            <text class="dot"></text>
          </template>
        </uni-list-item>
       </uni-list
    ></view>
  </scroll-view>
</template>

<style lang="scss" scoped>
  @import './styles.scss';
</style>
